home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / stormamiga_lib-v45_00d / include / sys / time.h < prev    next >
C/C++ Source or Header  |  2000-02-28  |  3KB  |  110 lines

  1. #ifndef SYS_TIME_H
  2. #define SYS_TIME_H
  3.  
  4. /*
  5. **        $VER: sys/time.h 1.3 (18.09.98)
  6. **            Includes Release 45.00
  7. **
  8. **    Copyright © 1996/2000 by CyberdyneSystems
  9. **
  10. **            written by Matthias Henze
  11. **               All Rights Reserved
  12. */
  13.  
  14. #ifndef STORMAMIGA_H
  15.   #include <stormamiga.h>
  16. #endif
  17. #ifndef _INCLUDE_TIME_H
  18.   #include <time.h>
  19. #endif
  20.  
  21. #ifdef __cplusplus
  22.   extern "C" {
  23. #endif
  24.  
  25. #ifndef DEVICES_TIMER_H
  26.   struct timeval
  27.   {
  28.     long    tv_sec;               /* seconds */
  29.     long    tv_usec;              /* microseconds */
  30.   };
  31. #else
  32.   #define tv_sec  tv_secs         /* seconds */
  33.   #define tv_usec tv_micro        /* nanoseconds */
  34. #endif
  35.  
  36. /* Structure defined by POSIX.4 to be like a timeval. */
  37. struct timespec
  38. {
  39.   time_t  ts_sec;                 /* seconds */
  40.   long    ts_nsec;                /* nanoseconds */
  41. };
  42.  
  43. #define TIMEVAL_TO_TIMESPEC(tv, ts) { (ts)->ts_sec = (tv)->tv_sec;                \
  44.                     (ts)->ts_nsec = (tv)->tv_usec * 1000; }
  45. #define TIMESPEC_TO_TIMEVAL(tv, ts) { (tv)->tv_sec = (ts)->ts_sec;                \
  46.                     (tv)->tv_usec = (ts)->ts_nsec / 1000; }
  47.  
  48. /* Operations on timevals. */
  49. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  50. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  51. #define timercmp(tvp, uvp, cmp) (((tvp)->tv_sec == (uvp)->tv_sec) ?               \
  52.                 ((tvp)->tv_usec cmp (uvp)->tv_usec) :             \
  53.                 ((tvp)->tv_sec cmp (uvp)->tv_sec))
  54. #define timeradd(tvp, uvp, vvp) do {                                              \
  55.                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;    \
  56.                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
  57.                 if ((vvp)->tv_usec >= 1000000) {                  \
  58.                   (vvp)->tv_sec++;                                \
  59.                   (vvp)->tv_usec -= 1000000; }                    \
  60.                 } while (0)
  61. #define timersub(tvp, uvp, vvp) do {                                              \
  62.                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;    \
  63.                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
  64.                 if ((vvp)->tv_usec < 0) {                         \
  65.                   (vvp)->tv_sec--;                                \
  66.                   (vvp)->tv_usec += 1000000; }                    \
  67.                 } while (0)   
  68.  
  69. /* Names of the interval timers, and structure defining a timer setting. */
  70. #define ITIMER_REAL     0
  71. #define ITIMER_VIRTUAL  1
  72. #define ITIMER_PROF     2
  73.  
  74. struct  itimerval
  75. {
  76.   struct  timeval it_interval;    /* timer interval */
  77.   struct  timeval it_value;       /* current value */
  78. };
  79.  
  80. /* Getkerninfo clock information structure */
  81. struct clockinfo
  82. {
  83.   int     hz;                     /* clock frequency */
  84.   int     tick;                   /* micro-seconds per hz tick */
  85.   int     tickadj;                /* clock skew rate for adjtime() */
  86.   int     stathz;                 /* statistics clock frequency */
  87.   int     profhz;                 /* profiling clock frequency */
  88. };
  89.  
  90. /*----- UNIX-functions -----*/
  91.  
  92. #ifndef _POSIX_SOURCE
  93.   int utimes  (cchar *, const struct timeval *);
  94. #endif
  95.  
  96. #ifdef __cplusplus
  97.   }
  98. #endif
  99.  
  100. #ifndef _POSIX_SOURCE
  101.   #ifdef STORMAMIGA_UNIXPATH
  102.     __inline int utimes_u (cchar *file, const struct timeval *times)
  103.     {return utimes        (file, times); }
  104.  
  105.     #define utimes(file, times) utimes_u(UnixToAmigaPath(file), times)
  106.   #endif
  107. #endif
  108.  
  109. #endif /* SYS_TIME_H */
  110.